home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Technotools
/
Technotools (Chestnut CD-ROM)(1993).ISO
/
lang_c
/
add_cs
/
add_cs.c
next >
Wrap
Text File
|
1987-07-31
|
4KB
|
154 lines
/*
Rather than providing you with an executable module, I am releasing
the source code. Since no two programmers want the same features,
you can customize the program so that you 'can have it your way.'
The only thing that I ask is that it NOT be used for commercial
ventures of ANY kind. No amount of modification and/or rewrite of
the source code will allow you to consider the resultant source code
to be your property.
Enjoy!
Eugene J. Alm
12145 West Luther Court
Hales Corners, Wisconsin, 53130
Copyright 1987 by Eugene J. Alm. All rights reserved. */
#include "stdio.h" /* fopen, fclose, fgets, fputs,
printf, fputchar */
#include "dos.h" /* unlink */
#include "stdlib.h" /* atoi, exit */
#include "io.h" /* access */
#define BUF_SIZ 256
FILE *in_data0, *in_data1, *out_data;
char buffer [BUF_SIZ];
enum exit_type { normal, error_exit };
void terminate (int, enum exit_type);
main (argc, argv)
int argc;
char *argv []; {
char *temp0;
int s_line, asm_line;
if (argc != 4) {
printf ("\n Invoke using:\n\n add_cs c_filename\
asm_filename result_filename\n\n Where:\n\n");
printf (" c_filename is the source file including the .c extension.\n\n");
printf (" asm_filename is the assembly language source file generated\n\
using TCC. The .asm extension must be supplied.\n\n");
printf (" result_filename is where the modified assembly language file\n\
is stored. If this file already exists, the run is aborted.");
exit (0);
}
if ((access (argv [3], 0)) == 0) {
printf ("\n\nThe file %s already exists.", argv [3]);
terminate (0, error_exit);
}
if ((in_data0 = fopen (argv [1], "r")) != NULL) {
if ((in_data1 = fopen (argv [2], "r")) != NULL) {
if ((out_data = fopen (argv [3], "w")) != NULL) {
temp0 = &buffer [0];
s_line = 0;
printf ("\n");
while ((fgets (buffer, BUF_SIZ - 1, in_data1)) != NULL) {
if (*temp0 != ';')
fputs (temp0, out_data);
else {
asm_line = atoi (temp0 + 7);
printf (".");
do {
fputs ("; * ", out_data);
if ((fgets (buffer, BUF_SIZ - 1, in_data0)) != NULL)
fputs (temp0, out_data);
else {
printf ("\nInput from %s terminated prematurely.", argv [1]);
terminate (3, normal);
unlink (argv [3]);
terminate (0, error_exit);
}
} while ((++s_line) < asm_line);
}
}
terminate (3, normal);
}
else {
printf ("\n\nCannot open %s.", argv [3]);
terminate (2, error_exit);
}
}
else {
printf ("\n\nCannot open %s.", argv [2]);
terminate (1, error_exit);
}
}
else {
printf ("\n\nCannot open %s.", argv [1]);
terminate (0, error_exit);
}
printf ("\n\nProcessing completed.\n");
exit (0);
}
void terminate (count, state)
int count;
enum exit_type state; {
if (count > 2)
fclose (out_data);
if (count > 1)
fclose (in_data1);
if (count > 0)
fclose (in_data0);
if (state == error_exit) {
printf (" Processing aborted.\n");
exit (1);
}
}
/* The following is an abbreviated version of the printf library
function. If you wish to use the "full blown" printf from the
library, comment out (or delete) printf as shown below. This was
done in this manner to make the executable file smaller. */
int printf (str)
char *str; {
char *temp0, **stack;
char c;
stack = &str;
while ((c = *str++) != 0) {
if (c == '%') {
str++;
temp0 = *++stack;
while ((c = *temp0++) != 0)
fputchar (c);
}
else
fputchar (c);
}
}